import { proxy } from "valtio";
import { userControllerGetUserInfo } from "../servers/api/user";

export const userInfoState = proxy<API.User>({
  id: 0,
  username: "",
  password: "",
  email: "",
  gender: "male",
  avatarId: 0,
  bio: "",
  role: 0,
  chatRecords: "",
  learningProgress: "",
  createdAt: "",
  updatedAt: "",
  isDeleted: false,
  avatarFile: undefined,
});

export const userInfoAction = {
  updateAvatr(avatarFile: API.CustomeFile) {
    userInfoState.avatarFile = avatarFile;
  },
  async validateUserInfo() {
    const { data } = await userControllerGetUserInfo();
    Object.assign(userInfoState, data);
  },
};
